<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link href="__PUBLIC__/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/lib/icheck/icheck.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/lib/Hui-iconfont/1.0.6/iconfont.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/lib/Validform/5.3.2/style.css" rel="stylesheet" type="text/css" />
<link href="Tpl/Admin/common/family/family.css" rel="stylesheet" type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>添加家庭</title>
</head>
<body>
<div class="pd-20">
<input type="hidden" id="idd" name="id" value="{$Think.session.authId}"/>
	<form action="" method="post" class="form form-horizontal" id="form_edit">
	
		<div class="row cl">
					<label class="form-label col-3">地址：</label>
					<div class="formControls col-5">
							<input type="hidden" name="id" value="{$data.id}" class="customerId">
							<span class="select-box mb-20">
								<select name="community_id" class="xiaoqu select" required="required">
	                           		<option value="" selected="true" disabled="true">请选择小区</option>
	                        	</select>
							</span>
							<span class="select-box mb-20">
								<select name="zone_id" class="quyu select" required="required">
	                            	<option value="" selected="true" disabled="true">请选择区域</option>
	                        	</select>
							</span>
	                        <span class="select-box mb-20">
		                        <select name="building_id" class="louhao select" required="required">
		                            <option value="" selected="true" disabled="true">请选择楼号</option>
		                        </select>
	                        </span>
	                       	<span class="select-box mb-20">
		                       	<select name="unit_id" class="danyuan select" required="required">
		                            <option value="" selected="true" disabled="true">请选择单元</option>
		                        </select>
	                       	</span>
	                        <span class="select-box mb-20">
		                        <select name="room_id" class="fangjian select" required="required">
		                            <option value="" selected="true" disabled="true">请选择房间号</option>
		                        </select>
	                        </span>
					</div>
					<div class="col-4"></div>
				</div>
		<div class="row cl">
			<label class="form-label col-3">人员身份：</label>
			<div class="formControls col-5">
				<span class="select-box mb-20">
					<select name="type" class="identity select" >
	               		<option value="">请选择身份</option>
	               		<option value="1" {$data['type']==1?'selected':''}>成员</option>
	               		<option value="2" {$data['type']==2?'selected':''}>业主</option>
	               		<option value="3" {$data['type']==3?'selected':''}>租客</option>
	            	</select>
				</span>
			</div>
		</div>
		<div class="row cl">
			<div class="col-9 col-offset-3">
				<input class="btn btn-primary radius" type="submit" id="formSub" value="提交">
			</div>
		</div>


	</form>
	<div id="allmap"></div>
</div>
<script type="text/javascript" src="__PUBLIC__/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="__PUBLIC__/lib/icheck/jquery.icheck.min.js"></script> 	
<script type="text/javascript" src="__PUBLIC__/lib/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="__PUBLIC__/lib/layer/2.1/layer.js"></script> 
<script type="text/javascript" src="__PUBLIC__/js/H-ui.js"></script> 
<script type="text/javascript" src="__PUBLIC__/js/H-ui.admin.js"></script> 
<script type="text/javascript" src="__PUBLIC__/js/getUrl.js"></script> 
<script type="text/javascript" src="__PUBLIC__/lib/Validform/5.3.2/Validform.min.js"></script>
<script src="http://cdn.bootcss.com/jquery.form/3.51/jquery.form.min.js"></script>
<!-- <script type="text/javascript" src="Tpl/Admin/common/wechat/address_liandong.js"></script> -->
<script type="text/javascript">
		// 全局
		var info={
			tel:"",//呼入用户手机号
			id:$.getUrlVar('id'),//客户ID
			customerData:'',//
			xiaoquId:0,
			quyuId:0,
			louhaoId:0,
			danyuanId:0
		}

		$(function(){
			// info.tel=$.getUrlVar('tel');
			work.init();
		});

		var work={
	ddressNum:1,//地址栏个数
	dataAll:"",//总数据
	strAll:[],//初始select数据
	addressDivId:1,//当前操作地址uid
	addressCount:1,//当前地址数
	addressIndex:'',//弹窗索引
	/*·····························初始化························*/
	init:function(){
		this.eventListen();
		this.ajaxFunc();
		this.getSelect();
		this.getCommunityData();
		// this.formsub();
	},
	/*·····························DOM························*/
	
	ajaxFunc:function(){

			$("#form_edit").Validform({
            tiptype:2,
            ajaxPost:true,
            showAllError:true,
            beforeSubmit:function(curform){
            
                curform.ajaxSubmit({
                type:'POST',
                url:'{:U('Admin/WechatUser/editing')}',
                success:function(data){
                  console.log(status);
                  if(data.status==1){
                      layer.msg("修改成功");
                      var index = parent.layer.getFrameIndex(window.name);
                      setTimeout(function(){
                           parent.layer.close(index);
                      },1000);
                      parent.location.reload();

                  }else{
                    layer.msg(data.msg);
                  }
                  }
                });
             return false; 
            }
          });

	},
	eventListen:function(){
		
	  	//    第一级
	    $(".xiaoqu").change(function () {
	    
	//如果下一级元素有大于2个option那么就重置后续select
	        if($(".quyu").children('option').length>1){
	            $(this).nextAll().each(function(){
	                $(this).empty();
	            });
	           for(var i=0;i<work.strAll.length;i++){
	            $(this).nextAll().eq(i).html(work.strAll[i]);
	            } 
	        }
	        
	        info.xiaoquId = $(this).val();
	        console.log(info.xiaoquId);
	        if(work.strLength(work.dataAll[info.xiaoquId].data)>0){
	            var zones=work.dataAll[info.xiaoquId].data;
	            console.log(zones);
	            work.strAdd(zones,'quyu','zone');
	        }else{
	             work.msg('quyu','区域');
	             var build=work.dataAll[info.xiaoquId][0].data;
	             work.strAdd(build,'louhao');
	        }
	        
	    });
	    //    第二级
	    $(".quyu").change(function(){
	          info.quyuId = $(this).val();
	        var build=work.dataAll[info.xiaoquId]['data'][info.quyuId].data;
	        work.strAdd(build,'louhao','building');
	    });
	    //    第三级
	    $(".louhao").change(function(){
	          info.louhaoId = $(this).val();
	          var unit=work.dataAll[info.xiaoquId]['data'][info.quyuId]['data'][info.louhaoId].data;
	          console.log(unit);
	          work.strAdd(unit,'danyuan','unit');
	          for(x in unit){
	              if(unit[x]['unit_id']==0){
	                  $(".danyuan").find('option').eq(1).text('无单元');
	                  var room=work.dataAll[info.xiaoquId]['data'][info.quyuId]['data'][info.louhaoId]['data'][0].data;
	                   work.strAdd(room,'fangjian','room');
	              }
	          }
	    });
	        //    第四级
	    $(".danyuan").change(function(){
	         info.danyuanId = $(this).val();
	         if(info.danyuanId){
	             var room=work.dataAll[info.xiaoquId]['data'][info.quyuId]['data'][info.louhaoId]['data'][info.danyuanId].data;
	            work.strAdd(room,'fangjian','room');
	         }
	    });
	  	
			
	},
	/*·····························功能性函数························*/
	
	// 地址确定显示中文
	addressShow:function(communityName,zoneName,buildName,unitName,roomName){
		var str=communityName+zoneName+buildName+unitName+roomName;
		$(".add-"+work.addressDivId).find(".addressInput").val(str);
	},
	// 五级联动
	//获取数据并设置小区下拉
	getCommunityData:function(){
		var idd = $("#idd").val();
		$.get("/index.php?m=Admin&c=House&a=jsonId&id="+idd,function(data){
        work.dataAll=data.data;
        data=data.data;
        var str="";
        for(x in data){
            console.log(data[x]['community_name']);
            if(data[x]['community_name']){
                str+='<option value="'+data[x]['community_id']+'">'+data[x]['community_name']+'</option>';
            }
        }
        $(".xiaoqu").append(str);
       });
	},
	// 获取初始select的值
	getSelect:function(){
		 $(".xiaoqu").nextAll().each(function(){
            work.strAll.push($(this).html());
            });
	},
	 // 计算数组或对象的长度
    strLength:function(str){
        t=typeof(str);
        if(t=='string'){
            return str.length;
        }else if(t=='object'){
            var n=0;
            for(var i in str){
                n++
            }
            return n;
        }
     },
      // 下拉菜单字符串生成
    // data为数据，id为id索引值
    strAdd:function(data,id,key){
        var str="";
        for (x in data){
            if(data[x]['unit_id']==0){
                console.log('无单元号');
                 work.msg('danyuan','单元');
                 // break;
            }
            str+='<option value="'+data[x][key+'_id']+'">'+data[x][key+'_name']+'</option>';
        }
        switch(id){
            case 'xiaoqu':
                $("."+id).empty();
                $("."+id).append('<option value="" selected="true" disabled="true">请选择小区</option>');
                break;
            case 'quyu':
                $("."+id).empty();
                $("."+id).append('<option value="" selected="true" disabled="true">请选择区域</option>');
                break;
            case 'louhao':
                $("."+id).empty();
                $("."+id).append('<option value="" selected="true" disabled="true">请选择楼号</option>');
                break;
            case 'danyuan':
                $("."+id).empty();
                $("."+id).append('<option value="" selected="true" disabled="true">请选择单元</option>');
                break;
            case 'fangjian':
                $("."+id).empty();
                $("."+id).append('<option value="" selected="true" disabled="true">请选择房间号</option>');
                break;
        }
        $("."+id).append(str);
    },
	
      // 没有下一级属性时显示的信息
    msg:function(obj,id,msg){
        $(obj).next("."+id).find("option").text('无'+msg);
    }
	/*·····························插件初始化························*/
	// formsub:function(){
 //        $("#form_edit").ajaxSubmit({
	//         type:'POST',
	//         url:'/index.php?m=Admin&c=WechatUser&a=editing',
	//         success:function(data){
	//           console.log(status);
	//         	if(data.stat==1){
	//               layer.msg("修改成功");
	//               var index = parent.layer.getFrameIndex(window.name);
	//               setTimeout(function(){
	//                    parent.layer.close(index);
	//               },1000);
	//               parent.location.reload();
	//             // parent.window.location.href="/index.php?m=Service&c=Center&a=index&tel="+info.tel;
	//           }else{
	//             layer.msg(data.msg);
	//           }
	//           }
 //        });
	// }
}
</script>

</body>
</html>